import { join } from "path";
import defineConfig from "./defineConfig";
import { builtinModules } from "module";
import pkg from "../package.json";
import plugins from "./plugins";

export default defineConfig({
	plugins,
	esbuild: { target: "chrome" },
	mode: process.env.NODE_ENV,
	root: join(__dirname, "../src/preload"),
	build: {
		outDir: "p",
		lib: { entry: "p.coffee", formats: ["cjs"] },
		minify: process.env.NODE_ENV === "production",
		emptyOutDir: true,
		rollupOptions: {
			external: [
				"electron",
				...builtinModules.flatMap((p) => [p, `node:${p}`]),
				//...Object.keys(pkg.dependencies || {})
			],
			output: { entryFileNames: "[name].cjs" },
		},
	},
});
